package net.asfun.jvalog.vo;


public class Pager {
	
	private int start = 0;
	private int end = Setting.SIZE_PAGE;
	private int total = 0;
	
	private int prev = 0;//0 if no prev page
	private int next = 0;//0 if no next page
	private int index = 1;//start from 1
	private int count = 1;//start from 1
	
	public Pager(){
		
	}
	
	public Pager(int page) {
		setIndex(page);
	}
	
	public int getStart() {
		return start;
	}

	public int getEnd() {
		return end;
	}

	public int getTotal() {
		return total;
	}
	
	public void setTotal(int total) {
		this.total = total;
		if ( total % Setting.SIZE_PAGE == 0 && total != 0 ) {
			count = total / Setting.SIZE_PAGE;
		} else {
			count = 1 + total / Setting.SIZE_PAGE;
		}
		if ( count > index ) {
			next = index + 1;
		}
	}

	public void setIndex(int page) {
		if ( page < 1) {
			page = 1;
		}
		index = page;
		start = (index - 1) * Setting.SIZE_PAGE;
		end = index * Setting.SIZE_PAGE;
		prev = index - 1;
	}
	
	public int getIndex() {
		return index;
	}
	
	public int getCount() {
		return count;
	}
	
	public int getPrev() {
		return prev;
	}
	
	public int getNext() {
		return next;
	}

}
